package com.zhuifeng.search.mq;

import com.alibaba.fastjson.JSONObject;
import com.zhuifeng.search.domain.Product;
import com.zhuifeng.search.service.ISearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ProductMq {

    @Autowired
    private ISearchService searchService;

    @RabbitListener(queues = {"productPutaway"})
    public void productPutaway(String productJson){
        Product product = JSONObject.parseObject(productJson, Product.class);
        searchService.productPutaway(product);
    }

    @RabbitListener(queues = {"productSold"})
    public void productSold(String productJson){
        String productId = JSONObject.parseObject(productJson, String.class);
        searchService.productSold(productId);
    }
}
